package com.chuzhong.sf.gui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @Author 初衷.
 * @Date 2020/10/18
 * 添加按钮响应事件
 **/
public class MyButtonEditor_user extends DefaultCellEditor   {
    private MyButton button;

    private MyEvent event;

    public MyButtonEditor_user() {
        super(new JTextField());
        button = new MyButton("用户管理");
        Font font = new Font("宋体", Font.PLAIN, 20);//设置字体
        button.setFont(font);
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //这里调用自定义的事件处理方法
                event.invoke(e);
            }

        });

    }

    public MyButtonEditor_user(MyEvent e) {
        this();
        this.event = e;
    }
    /*
    重写编辑器方法，返回一个按钮给JTable
    */
    @Override
    public Component getTableCellEditorComponent(JTable table, Object value,
                                                 boolean isSelected, int row, int column) {
//      setClickCountToStart(1);
//将这个被点击的按钮所在的行和列放进button里面
        button.setRow(row);
        button.setColumn(column);
        return button;
    }


}
